package com.example.javasystem.controller;

import com.example.javasystem.entity.PreprocessingConfig;
import com.example.javasystem.result.ApiResult;
import com.example.javasystem.service.IDataPreprocessingService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/config")
public class ConfigController {

    @Autowired
    private IDataPreprocessingService dataPreprocessingService;

    @ApiOperation("获取当前数据预处理配置")
    @GetMapping("/preprocessing")
    public ApiResult getPreprocessingConfig() {
        return ApiResult.success(dataPreprocessingService.getCurrentConfig());
    }

    @ApiOperation("更新数据预处理配置, 1/0持久化存储选项")
    @PostMapping("/preprocessing/{storage}")
    public ApiResult updatePreprocessingConfig(@RequestBody PreprocessingConfig config, @PathVariable Integer storage) {
        if(dataPreprocessingService.updateConfig(config, storage))
            return ApiResult.success("配置更新成功");
        else return ApiResult.error(500, "配置更新失败");
    }
}